package com.threadpool.mythread.case01;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author 李李李
 * @2020/4/25 21:43
 *
 * 线程安全的集合包 Map Set 相同道理
 *
 */
public class Case03 {
    public static void main(String[] args) {
        //定义 List 对象
        //List<String> list = new ArrayList<>(10);  // result ConcurrentModificationException 并发修改异常
        //List<String> list = new Vector<>(10);
        //List<String> list = Collections.synchronizedList(new ArrayList<>(10));
        List<String> list = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 110; i++){
            new Thread(()->{
                list.add(UUID.randomUUID().toString().replace("-",""));
                System.out.println(list);
            },String.valueOf(i)).start();
        }
    }
}
